

--可能有部分单位不能复制，比如畸变体，后面的具体看怎么处理
local disable_map = {
    ['畸变体'] = true,
}

local mt = ac.skill['灵魂收割']
function mt:on_enable()
    local py = self.owner:get_owner()
    local home = py:get_data('家')

    self.treg = ac.game:event '战斗-结束' (function()
        --敌人的家
        local ep = ac.battles[py:get_id()].target
        local enemy_home = ep:get_data('家')
        
        --从敌人的阵容里拿一个单位
        local name_list = {}
        for k,card in ipairs(enemy_home:get_all_card()) do
            for k, name in ipairs( card.name_list) do
                if not disable_map[name] then
                    table.insert( name_list, name)
                end
            end
        end
        if #name_list <= 0 then return end
        --从敌人上一局的阵容里取一个随机单位名字
        local name = name_list[math.random(1,#name_list)]

        local card = home:get_random_card()
        if not card then
            --没有卡牌，跳过
            return
        end

        card:add_unit(name)
    end)
end

function mt:on_disable()
    if self.trg then
        self.trg:remove()
    end
end




local mt = ac.skill['急速冻结']

function mt:on_can_cast()
    local py = self.owner:get_owner()
    local home = py:get_data('家')
    local target = self.target
    local card = target._card
    if not card then
        return false, '目标不是卡牌'
    end
    if card.is_hero then 
        return false, '不能对英雄使用'
    end 
    if card:get_place() ~= '商店区' then
        return false, '请选择商店区的卡牌'
    end
    if card.owner ~= py then
        return false, '无法选择其他玩家的卡牌'
    end
    if py:get('金币') < self.gold then
        return false,'金币不足'
    end
    return true
end

function mt:on_cast_shot()
    local py = self.owner:get_owner()
    local home = py:get_data('家')
    local target = self.target
    local card = target._card
    
    --扣金币
    py:add('金币',-self.gold)
    --锁卡
    card:change_store_lock()

    if card.is_store_lock then
        for k,v in ipairs(card.unit_list) do
            v:add_buff '召唤师-急速冻结'{
                skill = self,
            }
        end
    else
        for k,v in ipairs(card.unit_list) do
            v:remove_buff '召唤师-急速冻结'
        end
    end
end



local mt = ac.buff['召唤师-急速冻结']
function mt:on_add()
    local unit = self.target
    local skl = self.skill
    self.trg = ac.game:event '战斗-结束' (function()
        unit:add('生命上限',30)
        unit:add('基础攻击',4)
    end)
end

function mt:on_remove()
    self.trg:remove()
    self.trg = nil
end


